import { Provider as RProvider } from "mobx-react";
import React, { Component } from "react";
import { View, Text } from "react-native";
import CodePush from "react-native-code-push";
import { AppContainer } from "./src/navigators/AppNavigators";
import Loading from "./src/pages/common/Loading";
import * as store from "./src/store";
import { navigator } from "./src/utils";
import { logger } from "./src/utils/util";
import moment from "moment";
import "moment/locale/zh-cn";
import { MenuProvider } from "react-native-popup-menu";
import Upgrade from "./src/pages/Upgrade";
import { init, setNeedAddress, setOnceLocationLatest } from "react-native-amap-geolocation";
import { Provider } from "@ant-design/react-native";
import PermissionNotice from "./src/pages/common/permission/PermissionNotice";
// import { AMapSdk } from "react-native-amap3d";
// import { Platform } from 'react-native';
import backgroundTimePlugin from "./src/plugins/backgroundTimer";
import SeekOrderTipDialog from "./src/pages/seek-order/SeekOrderTipDialog";
class App extends Component {

  constructor(props) {
    super(props)
    this.state = {
      count: 0,
      lon: '',
      lat: ''
    }
  }

  componentDidMount() {

    /*
     如果不是在根组件的componentDidMount()方法通过codePush.sync()方法进行更新检查与安装，
     比如像我在设置中通过一个检查更新按钮，这时候就需要十分小心了。
     必须在根组件的componentDidMount()方法中添加 codePush.notifyAppReady()，否则应用会出现第一次重启是更新版，第二次重启又回滚到旧版的现象。
     */
    CodePush.notifyAppReady();

    // moment.locale('zh-cn');
    moment.updateLocale("zh-cn", {
      months: "一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月".split("_"),
      monthsShort: "1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月".split("_"),
      weekdaysShort: "周日_周一_周二_周三_周四_周五_周六".split("_"),
    });
    //注册微信
    // wechat.registerApp('wxde564822a9a17cf9', 'https://cat.aaaaa.in/report/');
    init({
      android: "e57d07ada137b7561c2e856f54841888",
      ios: "32de6b353075f87612e19487bdabf65b",
    }).catch(logger);
    // AMapSdk.init(
    //   Platform.select({
    //     android: "e57d07ada137b7561c2e856f54841888",
    //     ios: "32de6b353075f87612e19487bdabf65b",
    //   })
    // );
    setNeedAddress(true);

    // this.initJPush();
    // Pinyin.init();

    backgroundTimePlugin.init();
  }

  componentWillUnmount = () => {
    backgroundTimePlugin.clear();
    backgroundTimePlugin.reset();
  }

  initJPush = () => {
    // JPush.init();
    // //连接状态
    // this.connectListener = result => {
    //     logger("极光连接:" + JSON.stringify(result))
    // };
    // JPush.addConnectEventListener(this.connectListener);
    // //通知回调
    // this.notificationListener = async (result) => {
    //     logger("notificationListener:" + JSON.stringify(result))
    //     const loginInfo = await storage.load({
    //         key: 'session'
    //     }).catch((err) => {
    //         Log(err)
    //     });
    //     let extras = result.extras;
    //     if (result.notificationEventType == "notificationArrived" || IsNullOrEmpty(loginInfo) || IsNullOrEmpty(extras.jumpType)) { //没有登录或者没有附加参数 非点击弹框 不执行信息跳转
    //         return;
    //     }
    //
    //     if (extras.jumpType == 1) {//内容
    //         navigator.navigate('Html', {
    //             title: result.content,
    //             htmlContent: "",
    //             time: "",
    //             noticeID: extras.noticeId,
    //             refresh: () => {
    //             },
    //         })
    //     } else {//链接
    //         navigator.navigate('H5Page', {
    //             url: extras.jumpUrl, title: result.content, noticeID: item.id,
    //             refresh: () => {
    //             }
    //         });
    //     }
    // };
    // JPush.addNotificationListener(this.notificationListener);
  };

  render() {

    return (
      <RProvider {...store}>
        <Provider>
        <MenuProvider>
          <View style={{ flex: 1 }}>
            <AppContainer style={{ flex: 1 }}
                          ref={navigatorRef => {
                            navigator.setTopLevelNavigator(navigatorRef);
                          }}
            />
            <Loading />
            <Upgrade />
          </View>
        </MenuProvider>
        <PermissionNotice></PermissionNotice>
        <SeekOrderTipDialog></SeekOrderTipDialog>
        </Provider>
      </RProvider>
    );
  }
}

export default App;
